<?php
	
	class Longtext0v0r00_blob extends _smuoiDbRowExtended{
	
		protected $table = 'longtext';
		
		protected $get_functions = 'blob,link';
		protected $set_functions = 'blob,blb,link';
	
		function link(){
			return ($this->data->lnk) ? $this->pkg->db->get($this->data->lnk) : false;	
		}
		
		function blob(){
			if(!$this->data->blb instanceof sjo) $this->hard_set('blb', new sjo($this->data->blb));
			return $this->data->blb;
		}
		
		function set_blob($d){
			$this->edits['blb'] = new sjo($d);
			return false;
		}
		
		function set_blb($d){
			switch(true){
				case (!$d):
					$this->blob()->clear();
					return true;
				case is_scalar($d):
					$this->blob()->set_string($d);
					return true;
				case ($d === $this->blob()):
					return true;
				default:
					$this->blob()->set($d);
					return true;
			}
		}
		
		function set_link($l){
			if($l instanceof _smuoiDbRow) $l = $l->id;
			$this->hard_set('lnk', $l);
			return true;
		}
		
		protected function prepare_commit(){
			$this->run_set_functions();
			if(!$this->data->blb || (($this->data->blb instanceof sjo) && $this->blob()->is_empty())){
				$this->destroy();
				return false;
			}
			return true;
		}
		
		function get_string(){
			return (string) $this->blob();	
		}
		
		protected function destroy(){
			$this->pkg->db->delete($this->id);
		}
		
	}

?>